package LeetCode.month01.day28;
import java.util.*;

public class No2200 {
    public static void main(String[] args) {
        System.out.println(findKDistantIndices(new int[]{2,2,2,2,2},2,2));
    }
    public static List<Integer> findKDistantIndices(int[] nums, int key, int k) {
        int n = nums.length;
        List<Integer> list = new ArrayList<>();
        boolean[] flag = new boolean[n];
        for (int i = 0; i < n; i++) {
            if(nums[i]==key){
                for (int j = Math.max(0,i-k); j < n&&j<=i+k; j++) {
                    if(!flag[j]){
                        list.add(j);
                        flag[j]=true;
                    }
                }
            }
        }
        return list;
    }

}
